/**
 * C Programming: A Modern Approach
 *
 * version: 2nd
 * author: K.N.King
 * http://knking.com/books/c2
 */

#include <limits.h>
#include <stdio.h>

/**
 *
 */

int main(void) {
    int num = 0;
    int rev = 0;

    printf("Enter a number: ");
    scanf("%d", &num);
    if (num > INT_MAX || num < INT_MIN) {
        printf("Error: Invalid number");
        return 0;
    }

    while (num != 0) {
        int pop = num % 10;
        num /= 10;
        if (rev > INT_MAX / 10 || (rev == INT_MAX / 10 && pop > 7)) {
            return 0;
        }
        if (rev < INT_MIN / 10 || (rev == INT_MIN / 10 && pop < -8)) {
            return 0;
        }
        rev = rev * 10 + pop;
    }

    printf("The reversal is: %d\n", rev);

    return 0;
}

/*
output:
Enter a two-digit number: 28
The reversal is: 82
*/